package it.uniroma3.dia.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;

public class LoadProperties {
	
	public static List<String> getUtenti() {
		List<String> listUtenti = new LinkedList<String>();
		Properties prop = new Properties ();
		InputStream is = null;
		
		try {
			is = new FileInputStream ("prop.properties");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			prop.load (is);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		String utenti = prop.getProperty("utenti");
		
		StringTokenizer st = new StringTokenizer(utenti, ",");
		
		while(st.hasMoreTokens()){
			listUtenti.add(st.nextToken());
		}

		try {
			is.close ();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		
		return listUtenti;
	}
	
	public static List<String> getRootUser() {
		List<String> listUtenti = new LinkedList<String>();
		Properties prop = new Properties ();
		InputStream is = null;
		
		try {
			is = new FileInputStream ("prop.properties");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			prop.load (is);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		String utenti = prop.getProperty("rootUser");
		
		StringTokenizer st = new StringTokenizer(utenti, ",");
		
		while(st.hasMoreTokens()){
			listUtenti.add(st.nextToken());
		}

		try {
			is.close ();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		
		return listUtenti;
	}

	public static int getMaxProfondita() {
		Properties prop = new Properties ();
		InputStream is = null;
		
		try {
			is = new FileInputStream ("prop.properties");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			prop.load (is);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		int maxProf = Integer.parseInt(prop.getProperty("max_profondita"));
		
		return maxProf;
	}

	public static String getString(String str) {
		Properties prop = new Properties ();
		InputStream is = null;

		try {
			is = new FileInputStream ("prop.properties");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			prop.load (is);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		String str_ret = prop.getProperty(str);

		return str_ret;
	
	}

	public static String getNomeUtente() {
		return getString("nome_utente");
	}

	public static String getPassword() {
		return getString("password");
	}

	public static String getUrl() {
		return getString("url_db");

	}

	public static String getNomeDb() {
		// TODO Auto-generated method stub
		return getString("nome_db");
	}

	public static String getConsumerKey() {
		// TODO Auto-generated method stub
		return getString("consumer_key");
	}

	public static String getConsumerSecret() {
		// TODO Auto-generated method stub
		return getString("consumer_secret");
	}

	public static String getAccessToken() {
		// TODO Auto-generated method stub
		return getString("access_token");
	}

	public static String getTokenSecret() {
		// TODO Auto-generated method stub
		return getString("token_secret");
	}
	
	public static String getTypeOfOperation(){
		return getString("typeOfOperation");
	}
	public static String getAmiciDaVisitare(){
		return getString("amiciDaVisitare");
	}
	
	public static String getPathUtente(){
		return getString("pathUtente");
	}
	
	
	

}
